package com.ls.thread;

/**
 * 测试有超时时间的等待状态
 */
public class ThreadDemo4 {
    private static final Class<ThreadDemo4> LOCK = ThreadDemo4.class;
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            synchronized (LOCK){
                System.out.println("线程wait前");
                try {
                    // 避免死锁吧？
                    LOCK.wait(1000*30);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("其他线程唤醒后执行");
            }
        }, "t1");

        System.out.println(String.format("t1 state:{%s}",t1.getState()));
        t1.start();
        System.out.println(String.format("t1 state:{%s}",t1.getState()));
        // 唤醒前的状态
        System.out.println(String.format("t1 state:{%s}",t1.getState()));
        // 主线程唤醒t1
        synchronized (LOCK){
            LOCK.notify();
        }
        System.out.println(String.format("t1 state:{%s}",t1.getState()));
    }
}
